package com.hp.his.basic.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hp.his.basic.dao.ExamDao;
import com.hp.his.basic.dao.QuestionDao;
import com.hp.his.basic.dao.UPMSPageDao;
import com.hp.his.basic.dao.UPMSIssueDao;
import com.hp.his.basic.dao.UserDao;
import com.hp.his.basic.entity.ExamDetail;
import com.hp.his.basic.entity.ExamSummary;
import com.hp.his.basic.entity.Favorite;
import com.hp.his.basic.entity.Question;
import com.hp.his.basic.entity.UPMSPage;
import com.hp.his.basic.entity.UPMSIssue;
import com.hp.his.basic.entity.User;
import com.hp.his.core.orm.Page;
import com.hp.his.core.util.ServiceException;

/**
 * 基础数据字典的Manager
 * @author xuxians
 */
@Service
@Transactional
public class UPMSBaseManager {

	@Autowired
	private UPMSPageDao pageDao;
	@Autowired
	private UPMSIssueDao issueDao;
	
	@Autowired
	private ExamDao examDao;
	
	@Autowired
	private UserDao userDao;
	
	@Autowired
	private QuestionDao questionDao;

	private static  Logger logger = LoggerFactory.getLogger(UPMSBaseManager.class);
	
	public ExamDetail saveExam(ExamDetail exam){
		ExamDetail ex = examDao.saveReturn(exam);
		examDao.flush();
		return ex;
	}
	
	public Question saveQuestion(Question question){
		Question ques = questionDao.saveReturn(question);
		questionDao.flush();
		return ques;
	}
	
	public ExamDetail getExamById(Integer examId){
		return examDao.getExamById(examId);
	}
	
	public void deleteQuestion(Question question){
		questionDao.delete(question);
		questionDao.flush();
	}
	
	public void deleteExam(ExamDetail exam){
		examDao.delete(exam);
		examDao.flush();
	}
	
	public Question getQuestionById(Integer questionId){
		return questionDao.getQuestionById(questionId);
	}
	
	public User getUserByName(String userName){
		return userDao.getUserByName(userName);
	}
	
	public Page<UPMSPage> getAllPages(Page<UPMSPage> page){
		return pageDao.getAll(page);
	}
	
	public UPMSPage getUPMSPageById(Integer id){
		return pageDao.getPageByID(id);
	}
	
	public UPMSPage getUPMSPageByPageId(String pageId){
		return pageDao.getPageByPageID(pageId);
	}
	
	public void savePage(UPMSPage page){
		pageDao.saveReturn(page);
		pageDao.flush();
	}
	
	public Page<UPMSIssue> getAllIssues(Page<UPMSIssue> page){
		return issueDao.getAll(page);
	}	
	
	public UPMSIssue getUPMSIssueById(Integer issueId){
		return issueDao.get(issueId);
	}
	
	public List<ExamSummary> getCreatedExamList(Integer creatorId){
		return examDao.getExamListByUserId(creatorId);
	}
	
	public List<Favorite> getFavoriteListByUserId(Integer userId){
		return examDao.getFavoriteListByUserId(userId);
	}

}
